require("SOD/tools/dialogs/dialog.rb")
require("SOD/ProjectManager.rb")

module SOD
  
  class LoadVariantDialog < SOD_Dialog # see OS Dialog
    
    def initialize(interface, title = "Default", scrollbars = true, w = 660, h = 580, l = 150, t = 150)
      super
      set_file("LoadVariant.html")
      add_callbacks
    end
    
    def add_callbacks
      super
      @webDialog.add_action_callback("load") { |d, p| load(d, p) }
    end
    
    def load(d, p)
      args = p.split(",")
      key = args[0]
      value = args[1]
      
      if key == "SAVE"
        Plugin.projectManager.activeFileName = value
      else
        puts "LoadVariant: No new file loaded!" if $debug
      end
    end
    
    def update
      
      @projectName = Plugin.projectManager.activeProjectName
      @var1 = Plugin.projectManager.activeFileName
      @var1 = "No File Loaded!" if @var.nil?
      
      set_element_value("PROJECT", @projectName)
      set_element_value("VARIANT", @var1)
      
      fileNames = []
      Plugin.projectManager.projectFileList.each { |value| fileNames << value }
      
      set_select_options("LOAD", fileNames)
      
      #@hash['PROJECT'] = "Pname" #Plugin.projectManager.activeProjectName
      #@hash['VARIANT_1'] = "Vname" #Plugin.projectManager.activeFileName
      #@hash['VARIANT_2'] = "Vname" #Plugin.projectManager.activeFileName
      #
      #@hash.keys.each { |key| set_element_value(key, @hash[key]) }
    end
    
  end
  
end
